home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 15
/
Aminet 15 - Nov 1996.iso
/
Aminet
/
dev
/
basic
/
ace24dist.lha
/
ace24.lha
/
prgs
/
Misc
/
array_via_pointers.b
< prev
next >
Wrap
Text File
|
1996-09-11
|
963b
|
35 lines
'..Using pointers to implement an array of numbers
'..(single-precision values in this case).
{* Variables *}
ADDRESS memBlock
{* Subprograms *}
SUB SetElement(ADDRESS addr, LONGINT i, SINGLE x)
*!(addr + i*SIZEOF(SINGLE)) := x
END SUB
SUB SINGLE Element(ADDRESS addr, LONGINT i)
Element = *!(addr + i*SIZEOF(SINGLE))
END SUB
{* Main *}
'..Allocate a memBlock of N single-precision floats
INPUT "How many numbers? ",N
memBlock = ALLOC(N*SIZEOF(SINGLE))
IF memBlock = 0& THEN STOP
PRINT "Allocated";N;"values ( 0 to";N-1;")"
'..Fill "array" with the squares of i
FOR i=0 TO N-1
SetElement(memBlock, i, i*i)
NEXT
'..Display "array" elements
FOR i=0 TO N-1
PRINT i, Element(memBlock, i)
NEXT
END